home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Expander / Expander Classes / CExpandorama.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  4.6 KB  |  179 lines  |  [TEXT/KAHL]

  1. /***********************************************************************************
  2.     CExpandorama.cp
  3.  
  4.     Copyright © 1994 B-Ray Software. All rights reserved.
  5.     Developed using Symantec C++ 7.0.2 and Symantec's TCL library.
  6.     Portions of this code courtesy Symantec, Inc.
  7.  
  8.     This code may be freely distributed as long as this notice remains. This code
  9.     may not be used in any commercial software without the consent of B-Ray Software.
  10.  
  11.     ---
  12.  
  13.     CExpandorama provides functionality like CExpanderPane, but with a Panorama
  14.     twist. For most projects, this would be the root object in an Expander tree. There
  15.     really is no need for more than one of these in a window - all other subpanes
  16.     should be CExpanderPane derivatives.
  17.  
  18. ***********************************************************************************/
  19. #include "CExpandorama.h"
  20. #include "ExpanderMessages.h"
  21.  
  22.  
  23. TCL_DEFINE_CLASS_D2( CExpandorama, CPanorama, CColumnizer );
  24.  
  25.  
  26. /*
  27.  * CExpandorama constructor
  28.  *
  29.  * Default constructor - should only be called when created by a file read.
  30.  */
  31.  
  32. CExpandorama :: CExpandorama() : CPanorama(), CColumnizer()
  33. {
  34.     TCL_END_CONSTRUCTOR
  35. }
  36.  
  37.  
  38. /*
  39.  * CExpandorama constructor
  40.  *
  41.  * Normal constructor - should always be called when created in code.
  42.  */
  43.  
  44. CExpandorama :: CExpandorama( CView *anEnclosure, CBureaucrat *aSupervisor,
  45.                                 short aWidth, short aHeight,
  46.                                 short aHLoc, short aVLoc,
  47.                                 SizingOption aHSizing, SizingOption aVSizing )
  48.                     : CPanorama( anEnclosure, aSupervisor, aWidth, aHeight, aHLoc, aVLoc,
  49.                              aHSizing, aVSizing ), CColumnizer()
  50. {
  51.     SetWantsClicks( TRUE );        // let user click on us - maybe an Expander present
  52.  
  53.     TCL_END_CONSTRUCTOR
  54. }
  55.  
  56.  
  57. /*
  58.  * CExpanderLabel destructor
  59.  *
  60.  * Just a place-holder for Inspector
  61.  */
  62.  
  63. CExpandorama :: ~CExpandorama()
  64. {
  65.     TCL_START_DESTRUCTOR
  66. }
  67.  
  68.  
  69. /*
  70.  * ChangeSelf method - OVERRIDE
  71.  *
  72.  * Called by CRowColumnMgr whenever a child has changed size. We get the new family size
  73.  * and adjust our bounds to reflect the new size.
  74.  */
  75.  
  76. void CExpandorama :: ChangeSelf( long changedIndex, Rect *delta )
  77. {
  78.     LongRect    newBounds;
  79.     short        aHeight, aWidth;
  80.  
  81.     GetFamilySize( &aWidth, &aHeight );
  82.  
  83.     newBounds.top = 0;
  84.     newBounds.left = 0;
  85.     newBounds.bottom = aHeight / vScale;
  86.     newBounds.right = aWidth / hScale;
  87.     SetBounds( &newBounds );
  88.     Refresh();
  89.  
  90.     TellParent( kRowColChildChanged, delta );    // gotta let our parent know too
  91. }
  92.  
  93.  
  94. /*
  95.  * ChildMessage method - OVERRIDE
  96.  *
  97.  * Handles kExpanderChildSelect messages just like CExpanderPane except that we also
  98.  * scroll to the selected child if it is not visible.
  99.  */
  100.  
  101. void CExpandorama :: ChildMessage( CFamily *aChild, long message, void *param )
  102. {
  103.     if ( message == kExpanderChildSelect ) {
  104.         if ( itsParent ) {                        // still can go up the tree
  105.             TellParent( message, param );
  106.         }
  107.         else {                                    // at root of tree - handle it here
  108.             if ( param ) {                        // we have a valid child
  109.                 CPane        *aPane = ((CFamily *)param)->ChildToPane();    // get pane for child
  110.                 LongRect    aFrame;
  111.                 aPane->GetFrame( &aFrame );        // get child's frame
  112.                 do {                            // keep converting child's frame to its ancestors
  113.                     aPane->FrameToEnclR( &aFrame );
  114.                     aPane = (CPane *)(aPane->itsEnclosure);
  115.                 } while ( aPane != this );        // until we are reached
  116.  
  117.                 MakeSelectionVisible( &aFrame );    // see that the given rect is visible
  118.             }
  119.             TellChildren( message, param );        // pass along the select message to our children
  120.         }
  121.     }
  122.     else {
  123.         CColumnizer::ChildMessage( aChild, message, param );
  124.     }
  125. }
  126.  
  127.  
  128. /*
  129.  * MakeSelectionVisible method
  130.  *
  131.  * Makes sure that the given rect is entirely visible in the panorama. If not,
  132.  * it scrolls so that it is.
  133.  */
  134.  
  135. void CExpandorama :: MakeSelectionVisible( LongRect *rect )
  136. {
  137.     LongPt    newPos;
  138.     short    hSpan, vSpan;
  139.     long    selectedPos;
  140.  
  141.     GetFrameSpan( &hSpan, &vSpan );
  142.     if ( ( selectedPos = rect->top / vScale ) < position.v ) {    // line is above viewable area
  143.         newPos.v = selectedPos;
  144.         newPos.h = position.h;
  145.         ScrollTo( &newPos, TRUE );
  146.     }
  147.     else if ( ( selectedPos = rect->bottom / vScale ) > position.v + vSpan ) {    // line is below viewable area
  148.         newPos.v = selectedPos - vSpan;
  149.         newPos.h = position.h;
  150.         ScrollTo( &newPos, TRUE );
  151.     }
  152. }
  153.  
  154.  
  155. /*
  156.  * PutTo method - OVERRIDE
  157.  *
  158.  * Writes to the stream all the info we need to save.
  159.  */
  160.  
  161. void CExpandorama :: PutTo( CStream &stream )
  162. {
  163.     CPanorama::PutTo( stream );                // let our CPanorama parent access stream
  164.     CColumnizer::PutTo( stream );            // let our CColumnizer parent access stream
  165. }
  166.  
  167.  
  168. /*
  169.  * GetFrom method - OVERRIDE
  170.  *
  171.  * Reads from the stream all of the info that we saved.
  172.  */
  173.  
  174. void CExpandorama :: GetFrom( CStream &stream )
  175. {
  176.     CPanorama::GetFrom( stream );        // let our CPanorama parent access stream
  177.     CColumnizer::GetFrom( stream );        // let our CColumnizer parent access stream
  178. }
  179.